"use strict";
/* Controllers */
app.controller("smartTokenListController", ['$scope', '$location', '$rootScope', '$routeParams', 'smartTokenListService', function ($scope, $location, $rootScope, $routeParams, smartTokenListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};
    vm.p.appID = $routeParams.appID; //  获取应用模块的名称

    var errorFn = function (result) {
        alert(result);
    };
    vm.conf = [];

    $scope.queryItems = function(id) {
        $scope.listMetricSource(id);
    };

    $scope.searchItems = function() {
        var vm = $scope.vm;
        vm.result.ms = "...";
        // 去除两端空格
        vm.p.search = vm.p.search.replace(/^\s+|\s+$/g,'');
        if(vm.p.search=='') {
            alert("请输入搜索表名称");
            return;
        }
        var params = {search: vm.p.search};
        var procFn = function (response) {
            if ("000" !== response.code) {
                alert(response.message);
                return ;
            }
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) {
                return;
            }
            vm.result.data = data;
            if(vm.p.search!='') {
                $('#list_table').bootstrapTable('showColumn', 'columnList');
            }
            $('#list_table').bootstrapTable('load', data);
        };

        smartTokenListService.listLogicTable(params, procFn, errorFn);
    }

    $scope.listLogicTable = function (topic) {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var params = {topic: topic};
        var procFn = function (response) {
            if ("000" !== response.code) {
                alert(response.message);
                return ;
            }
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) return;
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        smartTokenListService.listLogicTable(params, procFn, errorFn);
    };


    $scope.initializeController = function () {
        vm.result.ms = '';

        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });

//        $resultTable.bootstrapTable('hideColumn', 'columnList');

        $scope.listLogicTable();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('smartTokenListService', ['ajaxService', function (ajaxService) {

    this.listLogicTable = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/smartdq/listLogicTable.do", successFunction, errorFunction);
    };

}]);





